// --- Copyright (c) 2006-2008 Stefan Kyntchev ---
// This software is written and copyrighted by Stefan Kyntchev 
// and BeyondPod Team members. All rights are reserved.
// Author contact: support@beyondpod.mobi
// ------------------------------------------------------------------------
// This file is part of BeyondPod RSS Feed Reader and Podcast manager
// (www.codeplex.com/BeyondPod) 
// BeyondPod is free software: you can redistribute it and/or modify 
// it under the terms of the GNU General Public License as published by 
// the Free Software Foundation, either version 3 of the License, or 
// (at your option) any later version. 
//  
// BeyondPod is distributed in the hope that it will be useful, 
// but WITHOUT ANY WARRANTY; without even the implied warranty of 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
// GNU General Public License for more details. 
//  
// You should have received a copy of the GNU General Public License
// along with BeyondPod. If not, see <http://www.gnu.org/licenses/>
// ------------------------------------------------------------------------
// COPYRIGHT NOTICE: This copyright notice may NOT be removed, obscured or modified 
// without written consent from the author.
// --- End copyright notice --- 


using System;

namespace svs.Mobile.BeyondScheduler.Core.Objects.Operations
{
	public class OperationBluetooth : OperationBase, IEquatable<OperationBluetooth>
	{
		#region BTAction enum

		public enum BTAction
		{
			On,
			Off
		}

		#endregion

		public static readonly Guid OperationID = new Guid("{16076FEC-0C02-4314-B8C4-4FEDE4C83C80}");

		private BTAction _TurnTo = BTAction.Off;

		public OperationBluetooth() : base("Turn Bluetooth", "Turn Bluetooth On or Off", OperationID)
		{
		}

		public OperationBluetooth(BTAction action)
			: this()
		{
			TurnTo = action;
		}

		public override string Name
		{
			get { return base.Name + " " + TurnTo.ToString(); }
		}

		public BTAction TurnTo
		{
			get { return _TurnTo; }
			set { _TurnTo = value; }
		}


		/// <summary>
		/// Serilized state of teh Operation
		/// </summary>
		public override string SerializedData
		{
			get { return (TurnTo).ToString(); }
		}

		public override string Description
		{
			get { return Name; }
		}

		#region IEquatable<OperationBluetooth> Members

		public bool Equals(OperationBluetooth operationBluetooth)
		{
			if (operationBluetooth == null) return false;
			return Equals(_TurnTo, operationBluetooth._TurnTo);
		}

		#endregion

		public override void Execute()
		{
			base.Execute();
			CoreHelper.BthSetMode(TurnTo == BTAction.Off ? CoreHelper.RadioMode.Off : CoreHelper.RadioMode.On);
		}

		/// <summary>
		/// Creates an instance of the this operation, desrialized from the serilaized string
		/// </summary>
		/// <param name="serializadData"></param>
		/// <returns></returns>
		public override OperationBase CreateInstance(string serializadData)
		{
			BTAction action = BTAction.Off;

			if (!string.IsNullOrEmpty(serializadData))
				action = (BTAction) Enum.Parse(typeof (BTAction), serializadData, true);

			return new OperationBluetooth(action);
		}

		public override bool Equals(object obj)
		{
			if (ReferenceEquals(this, obj)) return true;
			return Equals(obj as OperationBluetooth);
		}

		public override int GetHashCode()
		{
			return _TurnTo.GetHashCode();
		}
	}
}